<template>
    <div>
<!--        element-ui Container 布局容器-->
        <el-container>
            <el-header class="homeHeader">
                <div class="title">微人事</div>
                <div>
                    <el-button icon="el-icon-bell" type="text" style="margin-right: 8px;color: #000000;" size="normal"
                               @click="goChat"></el-button>
<!--                    element-ui Dropdown下拉菜单 菜单项点击事件-->
                    <el-dropdown class="userInfo" @command="commandHandler">
                        <span class="el-dropdown-link">
                            {{user.name}}
<!--                            $store|sessionStorage中存放的用户信息-->
                            <i><img :src="user.userface" alt=""></i>
                        </span>
                        <el-dropdown-menu slot="dropdown">
<!--                            dropdown-item中的command对应commandHandler中的cmd-->
                            <el-dropdown-item command="userinfo">个人中心</el-dropdown-item>
                            <el-dropdown-item command="setting">设置</el-dropdown-item>
                            <el-dropdown-item command="logout" divided>注销登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </el-header>

            <el-container>
                <el-aside width="200px">
<!--                    NavMenu导航菜单 侧栏  unique-opened：保持一个子菜单的展开-->
                    <el-menu router unique-opened>
<!--                    遍历router/index.js中的routes数组-->
<!--					在routes中给Login和Home添加hidden：true，不被渲染-->
                        <el-submenu v-for="(item,index) in routes " :index="index +'' "
                                    v-if="!item.hidden" :key="index">
                            <template slot="title">
                                <i class="el-icon-location"></i>
                                <span>{{item.name}}</span>
                            </template>
<!--                            children为子菜单-->
                            <el-menu-item :index="child.path" v-for="(child,indexj) in item.children " :key="indexj">
                                {{child.name}}
                            </el-menu-item>
                        </el-submenu>
                    </el-menu>

                </el-aside>
                <el-main>
<!--                    如果当前为home页则不显示面包屑，否则继续-->
                    <el-breadcrumb separator-class="el-icon-arrow-right" v-if="this.$router.currentRoute.path!='/home'">
                        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
<!--                        获取当前路由的name属性-->
                        <el-breadcrumb-item>{{this.$router.currentRoute.name}}</el-breadcrumb-item>
                    </el-breadcrumb>
<!--                    首页显示-->
                    <div class="homeWelcome" v-if="this.$router.currentRoute.path=='/home'">
                        欢迎来到微人事！Home
                    </div>
                    <router-view class="homeRouterView "/>
                </el-main>
            </el-container>

        </el-container>
    </div>
</template>

<script>
    export default {
        name: "Home",
        data() {
            return {
                // user: JSON.parse(window.sessionStorage.getItem("user"))
            }
        },
        computed: {
            routes() {
                return this.$store.state.routes;
            },
            user() {
                return this.$store.state.user;
            }
        },

        methods: {
            commandHandler(cmd) {
                if (cmd == 'logout') {
                    //element-ui MessageBox消息弹框中的确认消息
                    this.$confirm('此操作将注销登录, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.getRequest("/logout");
                        // 清空登录信息
                        window.sessionStorage.removeItem("user")
                        //清空菜单项
                        this.$store.commit('initRoutes', [])
                        // 回到登录页
                        this.$router.replace("/")
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消操作'
                        });
                    });
                }else if (cmd == 'userinfo') {
                    this.$router.push('/hrinfo');
                }
            }
        }
    }
</script>

<style>
    /*样式 对应各标签内的class*/
    .homeRouterView{
        margin-top: 10px; /*上外边距  就是离上边多远的意思*/
    }

    .homeWelcome {
        text-align: center;
        font-size: 30px;
        font-family: 华文行楷;
        color: #409eff;
        padding-top: 50px;
    }

    .homeHeader {
        background-color: #00aeff;
        display: flex; /*布局方式为flex：弹性布局*/
        align-items: center; /*在交叉轴上的对齐方式为center：交叉轴的中点对齐。*/
        justify-content: space-between;/*在主轴上的对齐方式为space-between：两端对齐，项目之间的间隔都相等。*/
        padding: 0px 15px; /*内边距 默认依次是上右下左 三个值为上右下 两个值为上下和左右 单独一个值就是全部*/
        box-sizing: border-box; /*为元素指定的任何内边距和边框都将在已设定的宽度和高度内进行绘制*/

    }

    .homeHeader .title {
        font-size: 30px;
        font-family: 华文行楷, serif;
        color: white;
    }

    .homeHeader .userInfo {
        cursor: pointer; /*光标为一只手的模样*/
    }

    .el-dropdown-link img {
        width: 48px;
        height: 48px;
        border-radius: 24px; /*圆角边框 四个角为24px*/
        margin-left: 8px; /*左外边距*/
    }

    .el-dropdown-link {
        display: flex;
        align-items: center;
    }

</style>
